var showRoundRectListMenu = function(element){
	
		var option = initRightMenu(element);
		
		var listTypeLabel = dojo.create("div", {
			innerHTML: "Choose the type of the list: ",
			style: "padding-top: 10px; padding-bottom: 10px; font-size: 13px; color: #aaaaaa;",
			align: "left",
		});
		
		var listTypeSelector = dojo.create("select", {
 			id: "listTypeSelector",
 			onchange: function(){ 
 				var typeSelected = listTypeSelector.value;
 				
 				switch(typeSelected){
 				
 				case "Entity":
 					entityMenu(element);
 					addAttributeToElementInGUIDescriptor(GUIDescriptor, "listType", typeSelected.toLowerCase(), element.id);
 					break;
 				
 				case "Custom":
 					customMenu(element);
 					addAttributeToElementInGUIDescriptor(GUIDescriptor, "listType", typeSelected.toLowerCase(), element.id);
 					break;
 				
 				case "Data":
 					dataMenu(element);
 					addAttributeToElementInGUIDescriptor(GUIDescriptor, "listType", typeSelected.toLowerCase(), element.id);
 					break;
 				}
 				
 			}
 		});
		
		var emptyOption = dojo.create("option", {});
		var entityOption = dojo.create("option", {value: "Entity", innerHTML: "Entity"});
		var customOption = dojo.create("option", {value: "Custom", innerHTML: "Custom"});
		var dataOption = dojo.create("option", {value: "Data", innerHTML: "Data"});
 		
		listTypeSelector.appendChild(emptyOption);
		listTypeSelector.appendChild(entityOption);
		listTypeSelector.appendChild(customOption);
		listTypeSelector.appendChild(dataOption);
		
		option.appendChild(listTypeLabel);
		option.appendChild(listTypeSelector);
 		
 	};
 	
 	var entityMenu = function(element){
 		
 		var option = initRightMenu(element);
 		
 		var label1 = dojo.create("div", {
				innerHTML: "Choose the Entity of the list: ",
				style: "padding-top: 10px; padding-bottom: 10px; font-size: 13px; color: #aaaaaa;",
				align: "left",
			});
	 		
	 		var addListItemFromData = dojo.create("select", {
	 			id: "addListItemFromData",
	 			onchange: function(){ 
	 				var entitySelected = addListItemFromData.value;
	 				addListItemToRoundRectList(element, entitySelected);
	 				addAttributeToElementInGUIDescriptor(GUIDescriptor, "entity", entitySelected, element.id);
	 			}
	 		});
	 		
	 		for(var i=0; i<dataProvider.length; i++){
	 			var temp = dojo.create("option", {value: dataProvider[i].entityName, innerHTML: dataProvider[i].entityName});
	 			addListItemFromData.appendChild(temp);
	 		}
	 		
	 		label1.appendChild(addListItemFromData);
	 		
	 		option.appendChild(label1);
 	};
 	
 	var customMenu = function(element){
 		
 		var option = initRightMenu(element);
 		
 		var addButtonLabel = dojo.create("div",{
 			innerHTML: "Add item to the list: ",
 			style:  "font-size: 13px; color: #aaaaaa; min-height: 30px;",
 		});
 		
 		var addButtonButton = dojo.create("div", {style : "width:18px; height:18px; border: 1px solid #454545; background:#272727; text-align: center; color: #e6e6e6; font-weight: bold; cursor: pointer; float: right; margin-right: 10px;",
			innerHTML : "+",
		});
 		
 		dojo.connect(addButtonButton, "onclick", function(){ 
 			
 			var label = dojo.create("div", {
 				innerHTML: "Label of the item: ",
 				style: "padding-top: 10px; padding-bottom: 10px; font-size: 13px; color: #aaaaaa;",
 				align: "left",
 			}
 			);
 	 		
 	 		var labelInput = dojo.create("input", {type: "text",});	
 	 		
 	 		var addItemButton = dojo.create("button",{
 	 			innerHTML: "Add Item",
 	 			onclick: function(){
 	 				
 	 				var itemContainer = dojo.create("li", {id: "listItem" + elementsIdCounter});
 			 		elementsIdCounter++;
 			 		element.appendChild(itemContainer);
 			 		createElementMenu(itemContainer);
 	 				
 			 		var listItem = new dojox.mobile.ListItem({ label: labelInput.value, rightText: "Seleziona " + labelInput.value}, itemContainer.id);

 			 		insertIntoGUIDescriptor(GUIDescriptor, {element: "listItem", id: itemContainer.id, attributes:{label: labelInput.value , itemType: "custom"}, children: [], innerHTML: ""}, element.id);
 			 		
 			 		customMenu(element);
 	 			}
 	 		});
 	 		
 	 		option.appendChild(label);
 	 		option.appendChild(labelInput);
 			option.appendChild(addItemButton);
 		});
 		
 		option.appendChild(addButtonButton);
 		option.appendChild(addButtonLabel);
 		
 	};
 	
 	var dataMenu = function(element){
 		
 		var option = initRightMenu(element);
 		
 		var labelFormName = dojo.create("div",{
 			innerHTML: "Specify the form that is the source of information: ",
 			style:  "font-size: 13px; color: #aaaaaa;",
 		});
 		
 		var inputFormName = dojo.create("input",{type: "text",
 			onchange: function(){
 				
 				var fillRoundRectDataList = function(data){
 					var results = dojo.fromJson(data);
 					
 					dojo.query('#'+element.id + '> li').forEach(function(node, index, arr){
						dijit.byId(node.id).destroyRecursive();
					});
 									
 					for(var i=0; i<results.length; i++){
 						var itemContainer = dojo.create("li", {id: "listItem" + elementsIdCounter});
 	 			 		elementsIdCounter++;
 	 			 		element.appendChild(itemContainer);
 	 			 		createElementMenu(itemContainer);
 	 			 		
 	 			 		var listItem = new dojox.mobile.ListItem({ label: results[i].marca, rightText: results[i].modello, clickable: true, url: "http://localhost:8282/GUIEngine/rest/ws/auto/"+results[i].modello}, itemContainer.id);
 	 			 		listItem.startup();
 					}

 				};
 				
 				dojo.subscribe("newData/"+inputFormName.value, fillRoundRectDataList);
 				addAttributeToElementInGUIDescriptor(GUIDescriptor, "formSource", inputFormName.value, element.id);
 			},
 		});
 		
 		option.appendChild(labelFormName);
 		option.appendChild(inputFormName);
 	};
 	
 	var addListItemToRoundRectList = function(element, selectorValue){
 		
 		//cerco la entity che ho selezionato dalla select in che posizione si trova
 		var index = 0;
 		for(var m=0; m<dataProvider.length; m++){
 			if(dataProvider[m].entityName == selectorValue){
 				index = m;
 			}
 		}
 		
 		//se la entity trovata ha "instanziato" degli oggetti..
 		if(dataProvider[index].objects.length!=0){
	 	
	 		//per ogni oggetto instanziato..
	 		for(var i=0; i<dataProvider[index].objects.length; i++){
	 		
	 			var itemContainer = dojo.create("li", {id: selectorValue + elementsIdCounter});
		 		elementsIdCounter++;
		 		element.appendChild(itemContainer);
		 		createElementMenu(itemContainer);
		 		var listItem = null;
		 		
		 		var idAssociationView = generateAssociationView(selectorValue, dataProvider[index].objects[i][0].value, element.parentNode.id); //per ogni item aggiunto, crea la nuova pagina a cui deve riindirizzarsi se l'item ha un associazione con un altra entity
		 		
		 		//se la entity ha una relazione associata..
		 		if(idAssociationView!=null){
		 			listItem = new dojox.mobile.ListItem({label: dataProvider[index].objects[i][0].value, rightIcon: "mblDomButtonBlueCircleArrow", moveTo: String(idAssociationView), transition: "flip", icon: "img/folder.png"},itemContainer.id);
		 			var destinationView = getNumberOfView(listItem.moveTo);
		 			dojo.connect(listItem, "onClick", function(){ dojo.publish("/viewChanged", {destinationView: destinationView}); } ) ;
		 		}else{
		 			console.log(dataProvider[index].objects[i].value + " " + dataProvider[index].objects[i].attribute);
		 			listItem = new dojox.mobile.ListItem({label: dataProvider[index].objects[i][0].value, moveTo: idAssociationView, transition: "flip", icon: "img/last.png"},itemContainer.id);
		 		}
		 		
		 		listItem.startup();
	 		}
 		}
 	};
 	
 	var generateAssociationView = function(className, label, parentView){
 		
 		var pageRoot = "";
 		
 		for(var i=0; i<dataProvider.length; i++){
 			
 			if(dataProvider[i].entityName == className && dataProvider[i].relation.length != 0){
 				pageRoot = document.createElement("div");
 				pageRoot.id = "View" + String((numberOfPages + 1)); //classDiagram[i].association + "_" + label;
 				numberOfPages++;
 				
 				dojo.byId("pages").appendChild(pageRoot);
 				
 				var view = new dojox.mobile.View({},pageRoot.id);
 				view.startup();
 			
 				pageRoot.setAttribute("style", "width: 480px; height: 800px; background: #dddddd; left: 10px");
 				
 				var title = dojo.create("div", {id: "heading"+elementsIdCounter});
 				elementsIdCounter++;
 				pageRoot.appendChild(title);
 				createElementMenu(title);
 				
 				var heading = new dojox.mobile.Heading({label: label, back:"Back", moveTo: parentView, transition: "flip", }, title.id);
 				 			
 				heading.on("click",function(){ dojo.publish("/viewChanged", {destinationView: getNumberOfView(parentView)});});
 	
 				var pageSelector = dojo.byId("pageSelector");

 				var pageNum = document.createElement("option");
 				pageNum.setAttribute("value", String(numberOfPages));
 				pageNum.innerHTML = String(numberOfPages);

 				pageSelector.appendChild(pageNum);
 				
 				dojo.publish("/addNewWorkspacePage", {newPageNumber: numberOfPages} );
 			}
 		}
 		
 		return pageRoot.id;
 	};	